package com.video.service.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.video.entity.SearchLog;
import com.video.entity.Systemlog;
import com.video.mapper.SystemLogMapper;
import com.video.service.system.ISystemLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @Author ken
 * @Time 2018/11/8 15:31
 * @Version 1.0
 */
@Service
public class SystemLogServiceImpl implements ISystemLogService {

    @Autowired
    private SystemLogMapper systemLogMapper;

    @Override
    public int insertLog(Systemlog systemLog) {
        return systemLogMapper.insert(systemLog);
    }

    @Override
    public int deleteLog(Integer id) {
        return systemLogMapper.deleteById(id);
    }

    @Override
    public int deleteLogs(Integer[] ids) {
        if(ids != null) {
            for (Integer id : ids) {
                systemLogMapper.deleteBatchIds(Arrays.asList(ids));
            }
            return 1;
        }
        return 0;
    }

    @Override
    public int clearLog() {
        return systemLogMapper.clearLog();
    }

    @Override
    public List<Systemlog> queryAll() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.orderByDesc("time");
        return systemLogMapper.selectList(queryWrapper);
    }

    @Override
    public List<Systemlog> searchLog(SearchLog searchLog) {
        return systemLogMapper.searchLog(searchLog);
    }
}
